﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DBSourceToolsLib.CodeParser
{
    public class ParseFactory
    {
        public static ParseObject GetParseObject(string strValue, int iLineIdx, int iWordIdx)
        {
            ParseVerb oParseVerb = new ParseVerb(strValue, iLineIdx, iWordIdx);
            if (oParseVerb.IsLegal)
                return oParseVerb;
            ParseVariable oParseVariable = new ParseVariable(strValue, iLineIdx, iWordIdx);
            if (oParseVariable.IsLegal)
                return oParseVariable;
            ParseNewLine oParseNewLine = new ParseNewLine(strValue, iLineIdx, iWordIdx);
            if (oParseNewLine.IsLegal)
                return oParseNewLine;
            ParseTable oParseTable = new ParseTable(strValue, iLineIdx, iWordIdx);
            if (oParseTable.IsLegal)
                return oParseTable;
            ParseData oParseData = new ParseData(strValue, iLineIdx, iWordIdx);
            return oParseData;
        }

        public static bool IsCharacterRecognized(char oChar)
        {
            if (ParseBrace.computeValue(oChar) > -1)
                return true;
            //if (ParseNewLine.computeValue(oChar) > -1)
            //    return true;
            if (ParseSpace.computeValue(oChar) > 0)
                return true;
            if (ParseToken.computeValue(oChar) > 0)
                return true;
            return false;
        }

        public static bool IsVerb(string strValue)
        {
            if (ParseVerb.computeValue(strValue) > 0)
                return true;
            return false;
            //ParseVerb oParseVerb = new ParseVerb(strValue);
            //return oParseVerb.IsLegal;
        }

        public static bool IsVerb(string strCurrentValue, object oNextChar)
        {
            if (ParseVerb.computeValue(strCurrentValue, oNextChar) > 0)
                return true;
            return false;
        }

        internal static ParseObject GetParseObjectFromChar(char currChar, int iLineIdx, int iWordIdx)
        {
            if (ParseBrace.computeValue(currChar) > -1)
                return new ParseBrace(currChar, iLineIdx, iWordIdx);
            //if (ParseNewLine.computeValue(currChar) > -1)
            //    return new ParseNewLine(currChar, iLineIdx, iWordIdx);
            if (ParseSpace.computeValue(currChar) > 0)
                return new ParseSpace(currChar, iLineIdx, iWordIdx);
            if (ParseToken.computeValue(currChar) > 0)
                return new ParseToken(currChar, iLineIdx, iWordIdx);
            return null;
        }

        internal static bool IsNewLine(string strCurrentValue)
        {
            if (ParseNewLine.computeValue(strCurrentValue) > 0)
                return true;
            return false;
        }

        public static bool IsTable(string strCurrentValue, object oNextChar)
        {
            if (ParseTable.computeValue(strCurrentValue, oNextChar) > 0)
                return true;
            return false;
        }

        public static bool IsStringRecognized(string strCurrentValue, object oNextchar)
        {
            if (ParseVerb.computeValue(strCurrentValue, oNextchar) > 0)
                return true;
            if (ParseTable.computeValue(strCurrentValue, oNextchar) > 0)
                return true;
            if (ParseNewLine.computeValue(strCurrentValue) > 0)
                return true;
            return false;
        }
    }
}
